A little while ago I started work on a 3D engine contained entirely inside JavaScript's built-in 2D Canvas features. I had tried various 3D libraries, but all of them either had too much boilerplate, or tool little. I wanted an engine that I knew inside and out. An engine that would allow me to customize every tiny detail of whatever I happened to be making. One thing led to another and I found myself with a decent looking demo of a not-so-decent looking 3D engine.
The 3D engine started out how most do. I created a triangle... and then some more triangles... and then a simple OBJ parser... and before you know it the engine is done! Now, I know the 2D context wasn't made to render 3D images, but as long as it can do a little math and draw a triangle it may as well be perfect for writing a 3D engine in. Luckily I had a little prior experience with writing 3D engines as I have written several in the Scratch programming language before. Here is an early screenshot from the engine.

One major drawback of my engine is the fact that there are no fragment shaders. Without implementing some janky functions, I can only render sharp, flat, solid-colored triangles. Of course that doesn't mean I can't add lighting, it just won't be nearly as smooth. The next iteration will show off the lighting, colors, and multiple objects with independent transformations.

After I finished the 3D engine, I wanted to make a simple game in it to prove it works. I settled on asteroids and got to work. The first thing I worked on were the Sun and stars. The stars are random every time for more uniqueness. The Sun can be moved around the horizon, as well as perpendicular to it, which isn't actually used in the demo itself because it takes place in space and there is no horizon in space.
The lens flare effect on the sun is something I noticed in older 3D engines (eg. Roblox Studio 2007) but haven't seen in any new ones, despite it's nice and cheap effect that adds to realism (although realism isn't exactly attainable here) and just gives players something more to look at.

I also modelled a spaceship in Blender and used my custom OBJ parser to load it into the engine. Some quick maths let me make the camera follow the spaceship. The lense flare, Sun, stars, and ship exhaust are all made in Inkscape using it's handy gradient tool.
When all of that was finally sorted out, it was time to add the titular asteroids. I made sure to keep the triangle count low, but I don't think they impacted performance that much in the end. All they do is float around, spin randomly, and if they get too far out they redirect back to a closer area. It was here that I began to lose the motivation to implement all of the rest of the features, namely the bullets fired from the ship, because they require different rendering to look good and my engine just isn't quite up for that yet.
That said, I thought it would be pretty boring with just asteroids so I threw in a teapot for your own enjoyment.

With the aforementioned technical limitations, it is less of a game and more of a demo. If you want, you can check it out here.
I had a lot of fun making the demo and thinking of ways to use my limitations while still making it look polished. I may keep working on the 3D engine, making more games or demos in it, and I'll probably add those to the site as I make them. There's a couple things I need to clean up with the code; The vector3 class is slapped in there when it really should be a library. Same goes for the entire engine itself. I just wrote a game on top of it instead of using it like a library as I most likely should've.
Who knows, maybe once my engine is a little more refined and sophisticated I'll come back and remake Space Flight Demo.
Created: 2026-07-25 19:44:04
Copyright ©2026 All Rights Reserved.